#include<bits/stdc++.h>
using namespace std;
priority_queue<int, vector<int>, greater<int> > priQue;
int main()
{
    int n, op, x;
    cin>>n;
    for(int i = 1; i <= n; ++i)
    {
        cin>>op;
        if(op == 1)
        {
            cin>>x;
            priQue.push(x);
        }
        else if(op == 2)
            cout<<priQue.top()<<endl;
        else
            priQue.pop();
    }
    return 0;
} 
